/* OSM layers for gvSIG. 
 * Geographic Information System of the Valencian Government
*
* Copyright (C) 2012 Nacho Brodin
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
* MA  02110-1301, USA.
* 
*/
package org.gvsig.raster.osm.cachestruct;

import java.awt.geom.Point2D;

/**
 * Limits of a tile matrix
 * @author Nacho Brodin (nachobrodin@gmail.com)
 */
public class TileMatrixLimits {
	private TileMatrix             tileMatrix           = null;
	private int                    minTileRow           = 0;
	private int                    maxTileRow           = 0;
	private int                    minTileCol           = 0;
	private int                    maxTileCol           = 0;
	
	public TileMatrix getTileMatrix() {
		if(tileMatrix == null)
			tileMatrix = new TileMatrix();
		return tileMatrix;
	}

	/**
	 * Gets the upper left corner and the lower right corner of the 
	 * selected tile
	 * @param x X tile position
	 * @param y Y tile position
	 * @return
	 */
	public Point2D[] getTileExtent(int x, int y) {
		double sizeXTile = getTileMatrix().getTileWidth() * getTileMatrix().getScaleXDenominator();
		double sizeYTile = getTileMatrix().getTileWidth() * getTileMatrix().getScaleYDenominator();
		double initX = getTileMatrix().getTopLeftCorner()[0] + (sizeXTile * x);
		double initY = getTileMatrix().getTopLeftCorner()[1] - (sizeYTile * y);
		Point2D[] p = new Point2D[2];
		p[0] = new Point2D.Double(initX, initY);
		p[1] = new Point2D.Double(initX + sizeXTile, initY - sizeYTile);
		return p;
	}
	
	public int getMinTileRow() {
		return minTileRow;
	}
	
	public void setMinTileRow(int minTileRow) {
		this.minTileRow = minTileRow;
	}
	
	public int getMaxTileRow() {
		return maxTileRow;
	}
	
	public void setMaxTileRow(int maxTileRow) {
		this.maxTileRow = maxTileRow;
	}
	
	public int getMinTileCol() {
		return minTileCol;
	}
	
	public void setMinTileCol(int minTileCol) {
		this.minTileCol = minTileCol;
	}
	
	public int getMaxTileCol() {
		return maxTileCol;
	}
	
	public void setMaxTileCol(int maxTileCol) {
		this.maxTileCol = maxTileCol;
	}
	
	public void print() {
		System.out.println("  *****TileMatrixLimits******");
		System.out.println("  MaxTileCol:" + getMaxTileCol());
		System.out.println("  MaxTileRow:" + getMaxTileRow());
		System.out.println("  MinTileCol:" + getMinTileCol());
		System.out.println("  MinTileRow:" + getMinTileRow());
		if(tileMatrix != null)
			tileMatrix.print();
	}
}
